home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98c.txt
/
000151_icon-group-sender _Mon Dec 21 09:39:52 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
1KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id JAA04197
for icon-group-addresses; Mon, 21 Dec 1998 09:39:46 -0700 (MST)
Message-Id: <199812211639.JAA04197@baskerville.CS.Arizona.EDU>
To: icon-group@optima.CS.Arizona.EDU
Date: Sun, 20 Dec 1998 01:02:51 GMT
From: static@operamail.com.au (Wade Bowmer)
Subject: Re: Small Icon programming problem
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
On 17 Dec 1998 13:21:34 -0500, Ralph Griswold <ralph@baskerville.CS.Arizona.EDU> wrote:
> Here's a small Icon programming problem for you to tackle:
>
> Write a procedure digsort(i) that returns the integer that
> results from sorting the digits of i, preserving sign. For
> example, digsort(201) should return 12 and digsort(-1042)
> should return -124. You may assume i is an integer.
>
> You could aim for brevity, speed, and/or clarity.
I dunno what to aim for. However, trying it out raises a question: what is digsort(737) supposed to produce? 377 or 37?
My solution outputs the former.
procedure digsort(in)
s := string(in) | return fail
t := table(0)
every t[!s] +:= 1
s := ""
every i := !sort(t,1) do
s ||:= repl(i[1], i[2])
return integer(s)
end
Wade.